var serveStaticFile = require("./serveStaticFile.js");

function route(pathname, handle, response, request, postData) {
    //handle[pathname]();不要默认对当前pathname就有处理程序，要先判断。
    console.log("About to route a request for " + pathname);
    if(typeof handle[pathname] === 'function') {
       handle[pathname](response, request, postData);
    }
    else if(pathname.length > 1) {
        console.log(pathname);
        serveStaticFile.serve(response,pathname);
    }
    else{
        console.log("no request handler for path " + pathname);
        response.writeHeader(404, {"Content-Type" : "text/plain"});
        response.write("404 Not Found");
        response.end();
    }
}

exports.route = route;